package com.bw.common.dialog

import android.content.Context
import android.content.DialogInterface
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.WindowManager
import android.widget.ImageView
import androidx.appcompat.app.AppCompatDialog
import com.bw.common.R

/**
 * App版本更新弹窗
 */
class AppUpdateDialog:AppCompatDialog {

    constructor(context: Context):super(context){

    }
    constructor(context: Context,them:Int):super(context,them)


    constructor(context: Context,cancelable:Boolean,cancelListener:DialogInterface.OnCancelListener):super(context,cancelable,cancelListener)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //设置布局
        setContentView(R.layout.app_update_layout)
        //设置取消事件
        findViewById<ImageView>(R.id.iv_update_close)?.setOnClickListener{
            cancel()
        }
        //修改样式
        var windowParams :WindowManager.LayoutParams = window?.attributes !!
        windowParams.apply {
            dimAmount = 0.3f //灰色区域明暗程度
            width = WindowManager.LayoutParams.MATCH_PARENT
            height = WindowManager.LayoutParams.MATCH_PARENT
        }
        window?.attributes = windowParams
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        //设置可以取消
        setCanceledOnTouchOutside(false)
        setCancelable(true)

    }

}